/*
 * Copyright (c) 2011 Junichiro Okuno
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are those of the
 * authors and should not be interpreted as representing official policies, either expressed
 * or implied, of Junichiro Okuno.
 */

package tcp_net.mail.pop3;

import tcp_net.*;
import tcp_net.mail.EmailHandler;
import tcp_net.mail.MailBoxFileManager;
import tcp_net.mail.EmailMessageProcessor;
import tcp_net.mail.pop3.states.*;
import tcp_net.mail.pop3.commands.POP3Command;
import tcp_net.mail.pop3.debug.DebugInfo;
import java.util.List;
import java.util.ArrayList;

/**
	This class provides a functionalities specific to POP3
	@author J. Okuno
*/
public class POP3MessageProcessor extends EmailMessageProcessor
{
	/**
		Debug information
	*/
	private final static boolean DEBUG = DebugInfo.POP3_MESSAGE_PROCESSOR_DEBUG;
	
	/**
		Init POP3MessageProcessor
		@param hd an email handler for this server
	*/
	public POP3MessageProcessor(EmailHandler hd) 
	{
		super(hd);
		DebugInfo.print(DEBUG,"POP3MessageProcessor created.");
		state = new Authorization();
	}
	
	/**
		This method processes a request (a command and arguments) from POP3 client
		@param message a line of a command and its arguments
	*/
	public List<String> process(String message)
	{
		DebugInfo.print(DEBUG, "POP3MessageProcessor starts");
		
		String str_command = analyser.getCommand(message);
		List<String> arguments = analyser.getArguments(message);
		
		return state.process(this, str_command, arguments);
	}
}